import Vue from 'vue'
import Router from 'vue-router'

// in development-env not use lazy-loading, because lazy-loading too many pages will cause webpack hot update too slow. so only in production use lazy-loading;
// detail: https://panjiachen.github.io/vue-element-admin-site/#/lazy-loading

Vue.use(Router)

/* Layout */
import Layout from '../views/layout/Layout'

/**
* hidden: true                   if `hidden:true` will not show in the sidebar(default is false)
* alwaysShow: true               if set true, will always show the root menu, whatever its child routes length
*                                if not set alwaysShow, only more than one route under the children
*                                it will becomes nested mode, otherwise not show the root menu
* redirect: noredirect           if `redirect:noredirect` will no redirct in the breadcrumb
* name:'router-name'             the name is used by <keep-alive> (must set!!!)
* meta : {
    title: 'title'               the name show in submenu and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar,
  }
**/
export const constantRouterMap = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },
  {
    path: '',
    component: Layout,
    redirect: '/dashboard',
    name: 'Dashboard',
    meta: { title: '控制面板', icon: 'example' },
    children: [
      {
        path: 'dashboard',
        component: () => import('@/views/dashboard/index'),
        meta: { title: '控制面板', icon: 'example' }
      }
    ]
  }
  //   { path: '*', redirect: '/404', hidden: true }
]

// 实例化vue的时候只挂载constantRouter
export default new Router({
  //   mode: 'history', // 后端支持可开
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRouterMap
})

// 异步挂载的路由
// 动态需要根据权限加载的路由表
export const asyncRouterMap = [
  {
    path: '/sales',
    component: Layout,
    redirect: '/sales/index',
    name: 'sales',
    meta: {
      title: '销售管理',
      icon: 'sales',
      role: ['sales_management', 'ordersale', 'salesafter']
    },
    children: [
      {
        path: 'index',
        name: 'shop_list',
        component: () => import('@/views/sales/index'),
        meta: {
          title: '订单维护',
          icon: 'shop_list',
          role: ['ordersale']
        }
      },
      {
        path: 'postSale',
        name: 'post_sale',
        component: () => import('@/views/sales/postSale'),
        meta: {
          title: '售后工单',
          icon: 'post_sale',
          role: ['salesafter']
        }
      }
    ]
  },
  {
    path: '/outbound',
    component: Layout,
    redirect: '/outbound/index',
    name: 'outbound',
    meta: {
      title: '出库管理',
      icon: 'outbound',
      role: ['outbound_management', 'outboundexpress', 'outboundkuaiyun']
    },
    children: [
      {
        path: 'index',
        name: 'express',
        component: () => import('@/views/outbound/index'),
        meta: {
          title: '快递维护',
          icon: 'express',
          role: ['outboundexpress']
        }
      },
      {
        path: 'giggit',
        name: 'giggit',
        component: () => import('@/views/outbound/giggit'),
        meta: {
          title: '快运维护',
          icon: 'giggit',
          role: ['outboundkuaiyun']
        }
      }
    ]
  },
  {
    path: '/express',
    component: Layout,
    redirect: '/express/index',
    name: 'express_company',
    meta: {
      title: '快递管理',
      icon: 'express_company',
      role: ['express_management', 'express']
    },
    children: [
      {
        path: 'index',
        name: 'express_company_list',
        component: () => import('@/views/express/index'),
        meta: {
          title: '快递列表',
          icon: 'express_company',
          role: ['express_management', 'express']
        }
      }
    ]
  },
  {
    path: '/stats',
    component: Layout,
    redirect: '/stats/chuku',
    name: 'stats',
    meta: {
      title: '数据统计',
      icon: 'datas',
      role: [
        'data_management',
        'outboundstatistics',
        'sendstatistics',
        'areastatistics'
      ]
    },
    children: [
      {
        path: 'chuku',
        name: 'chuku',
        component: () => import('@/views/stats/chuku'),
        meta: {
          title: '出库统计',
          icon: 'outbound',
          role: ['outboundstatistics']
        }
      },
      {
        path: 'shipments',
        name: 'shipments',
        component: () => import('@/views/stats/shipments'),
        meta: {
          title: '发货统计',
          icon: 'shipments',
          role: ['sendstatistics']
        }
      },
      {
        path: 'region',
        name: 'region',
        component: () => import('@/views/stats/region'),
        meta: { title: '地区统计', icon: 'region', role: ['areastatistics'] }
      }
    ]
  },
  {
    path: '/system',
    component: Layout,
    redirect: '/system/group',
    name: 'system',
    meta: {
      title: '系统管理',
      icon: 'system',
      role: [
        'system_management',
        'user',
        'material',
        'express_setting',
        'expressoutboundrules',
        'expresssplitrules'
      ]
    },
    children: [
      {
        path: 'group',
        name: 'group',
        component: () => import('@/views/system/group'),
        meta: { title: '系统用户', icon: 'users', role: ['user'] }
      },
      {
        path: 'supplies',
        name: 'supplies',
        component: () => import('@/views/system/supplies'),
        meta: { title: '物料管理', icon: 'supplies', role: ['material'] }
      },
      {
        path: 'priority',
        name: 'priority',
        component: () => import('@/views/system/priority'),
        meta: {
          title: '快递设置',
          icon: 'priority',
          role: ['express_setting']
        }
      },
      {
        path: 'chukuguize',
        name: 'chukuguize',
        component: () => import('@/views/system/chukuguize'),
        meta: {
          title: '出库规则',
          icon: 'outbound',
          role: ['expressoutboundrules']
        }
      },
      {
        path: 'split',
        name: 'split',
        component: () => import('@/views/system/split'),
        meta: { title: '拆分规则', icon: 'tree', role: ['expresssplitrules'] }
      }
    ]
  },
  {
    path: '/profile',
    component: Layout,
    redirect: '/profile/index',
    name: 'profile',
    hidden: true,
    meta: { title: '修改密码', icon: 'example' },
    children: [
      {
        path: 'index',
        component: () => import('@/views/profile/index'),
        meta: { title: '修改密码', icon: 'example' }
      }
    ]
  },
  {
    path: '/supplies/material',
    component: Layout,
    redirect: '/supplies/material/index',
    name: 'material',
    hidden: true,
    meta: { title: '物料对照表', icon: 'example', role: ['material'] },
    children: [
      {
        path: 'index',
        component: () => import('@/views/supplies/material/index'),
        meta: { title: '物料对照表', icon: 'example' }
      }
    ]
  },
  {
    path: '/priority',
    component: Layout,
    redirect: '/priority/index',
    name: 'priority_setting',
    hidden: true,
    meta: { title: '快递账号设置', icon: 'example', role: ['express_setting'] },
    children: [
      {
        path: 'index',
        component: () => import('@/views/priority/index'),
        meta: { title: '快递账号设置', icon: 'example' }
      }
    ]
  },
  { path: '*', redirect: '/404', hidden: true }
]
